//==================================================================================
//		Dual Quad Board Program
//		file name : Menu_Page1page0_Function.C
//		version : 1.0
//		target device : w78e516(winbond)
//		target board : dual quad board
//		c compiler : Keil
//==================================================================================


//void Main_Menu_On_Initial();
//void Main_Menu_Off_Initial();
//void Main_Menu_Select_Bar_Move();
//void Main_Menu_Bar_Display();
//void Menu_On_Off_Funtion();
#if 0
//==================================================================================
//
//
//
//
//
//==================================================================================
void Menu_On_Off_Funtion()
{
	if((key_code == MENU_KEY) && (zoom_mode_in == OFF))
	{
		led_on_off_flag = key_code;
		key_sound = ON;
//		led_on_off_data = 0x01;
		y_backup = -1;
		m_backup = -1;
		d_backup = -1;
		hh_backup = -1;
		mm_backup = -1;
		if(sub_menu_on == ON)
			sub_menu_on = OFF;
		else
			menu_on ^= 1;            //menu_on !=menu_on  (070823) 
		if((menu_on == ON) && (sub_menu_on == OFF))
		{
			Main_Menu_On_Initial();
		}
		else	 if((menu_on == OFF) && (sub_menu_on == OFF))
			Main_Menu_Off_Initial();
	}
}

//==================================================================================
//
//
//
//
//
//==================================================================================
void Main_Menu_On_Initial()
{
	RemoveBox();
	Event_Reset();
//	Init_Video();
//	Init_Page0();        //Initial page0 on there will influnce the picture be move to left a little 
//	Init_Page1();

	if(b_video_fmt == NTSC)
	{
		WriteAsicByte(MASTER, DVC_PG1, 0x00, 0x0c);		//... NTSC
		WriteAsicByte(SLAVE1, DVC_PG1, 0x00, 0x3d);
	}
	else
	{
		WriteAsicByte(MASTER, DVC_PG1, 0x00, 0x8c);		//... PAL
		WriteAsicByte(SLAVE1, DVC_PG1, 0x00, 0xbd);
	}

	WriteAsicByte(MASTER,DVC_PG1,0x0c,0x00);			//... Zoom Mode OFF //Need not changed,be used directly for tw2835
	WriteAsicByte(MASTER,DVC_PG2, 0x60, 0x00);			//... 2D Box On/OFF for 2DB0 for tw2835
	WriteAsicByte(MASTER,DVC_PG2, 0x68, 0x00);			//... 2D Box On/OFF for 2DB1 for tw2835
	WriteAsicByte(MASTER,DVC_PG2, 0x70, 0x00);			//... 2D Box On/OFF for 2DB2 for tw2835
	WriteAsicByte(MASTER,DVC_PG2, 0x78, 0x00);			//... 2D Box On/OFF for 2DB3 for tw2835
	
	Menu_Small_Mode_Display();                //Minimize the live picture ( PICHL);
	
//	WriteAsicByte(MASTER,DVC_PG1,0x06,0x80);	//... Mux Mode In //Enable MUX_MODE=1 for X path for tw2835 (070824)
//	WriteAsicByte(MASTER,DVC_PG1,0x07,0x10);	//...Set INTR_REQX=1 for X path for tw2835 (070824) (New added)


	WriteAsicByte(MASTER,DVC_PG2,0x1f,0x70);    //Set 2x1f (Alpha blending for Bitmap OSD and single box and blink time) 
//.......................................................................................................................	
//	if(b_video_fmt == NTSC)                       //Alread be changed for tw2835
//		WriteAsicByte(MASTER,DVC_PG1,0xa9,0x41);//0x01);	//... Encoder non-interlace NTSC Mode
//	else
//		WriteAsicByte(MASTER,DVC_PG1,0xa9,0x44);	//... Encoder non-interlace Pal Mode
//.......................................................................................................................
       menu_page0_main_menu_display();          //Not completely finished for tw2835
//       WriteAsicByte(MASTER,DVC_PG1,0xaa,0xaa);
//	WriteAsicByte(MASTER,DVC_PG1,0xa0,0x76);
//	WriteAsicByte(MASTER,DVC_PG1,0xa1,0x00);//0x32);	//... s-video (x path)	
//	WriteAsicByte(MASTER,DVC_PG1,0xa2,0xd7);	//... cvbs (y path)
//	WriteAsicByte(MASTER,DVC_PG1,0xa2,0x97);	//... cvbs (x path)
//	WriteAsicByte(MASTER,DVC_PG1,0xa3,0x01);	//... 656 output
	Main_Menu_Bar_Display();             //For the moment not used for test for tw2835
//	display_mode_change = 0;
	sub_menu_select_bar = 1;
	camera_number = 0;
//	vcr_mode_in = OFF;
//	vcr_zoom_on = OFF;
	zoom_mode_in = OFF;
//	freeze_on = OFF;	
}

//==================================================================================
//
//
//
//
//
//==================================================================================
void Main_Menu_Off_Initial()
{		
	RemoveOSDFnt(0, 0, 89, 287);                                  //Clear Box and Bitmap
	RemoveBox();

//	WriteAsicByte(MASTER,DVC_PG1,0x06,0x00);					//... Mux Mode Out  for X path (070824)
//	WriteAsicByte(MASTER,DVC_PG1,0x56,0x00);					//... Mux Mode Out  for Y path (070913)
//.......................................................................................................................
//	if(b_video_fmt == NTSC)                                                   //Already changed for tw2835 (070824)
//		WriteAsicByte(MASTER,DVC_PG1,0xa9,0x09);				//... Encoder interlace NTSC Mode
//	else
//		WriteAsicByte(MASTER,DVC_PG1,0xa9,0x4c);				//... Encoder interlace Pal Mode
		
//.......................................................................................................................	
//... 1x77 -> 0x01 non-interace mode  ntsc
//... 1x77 -> 0x09 interace mode

//... 1x77 -> 0x44 non-interace mode  pal
//... 1x77 -> 0x4c interace mode
//.......................................................................................................................

//+++++++++++++++++++++++++++++++
	Border_Line_Setup_Initial();
	Camera_Setup_Initial();
	Motion_Setup_Initial();
//+++++++++++++++++++++++++++++++

	
	menu_on = OFF;
	sub_menu_on = OFF;
//	display_mode_change = 0;
	main_menu_select_bar = 1;
	if(display_mode == REALTIME_8CH)
	{
		Display_8ch();
		led_on_off_flag =20;
	}else if(display_mode == REALTIME_8CH_M_A)
	{
		Display_8ch_AB();
		led_on_off_flag =18;
	}else if((display_mode == PIP2_MODE)||(display_mode == PIP1_MODE))
	{
		Display_PIP2_Function();
		led_on_off_flag =18;
	}
//	else if(display_mode == PIP1_MODE)
//		Display_PIP2_Function();
	else if(display_mode == SPLITE_2)
	{
		Display_Splite_2_Function();
		led_on_off_flag =18;
	}else if(auto_sequence_on == ON)
	{
		one_sec = 0;
		display_mode = QUAD_A;
		led_on_off_flag =17;
		return;
	}else if((display_mode == QUAD_A) ||(display_mode == QUAD_B))
	{
		Display_Quad_Function(pip_full_ch, pip_sub_ch_1, pip_sub_ch_2, pip_sub_ch_3);	
		led_on_off_flag =19;
	}else{
		Display_Full(display_mode -2 -(display_mode-2)/5);
		led_on_off_flag =display_mode -2 -(display_mode-2)/5+9;
	}	
}
#endif

#if 0
//==================================================================================
//
//
//
//
//
//==================================================================================
void Main_Menu_Select_Bar_Move()
{
	U8 i;
	
	if((key_code == DOWN_KEY) ||(key_code == RIGHT_KEY))
	{
		key_code = 0;
		key_sound = ON;
		main_menu_select_bar++;
		if(main_menu_select_bar > 7)
			main_menu_select_bar = 1;
		Main_Menu_Bar_Display();
	}
	else if((key_code == UP_KEY) || (key_code == LEFT_KEY))
	{
		key_code = 0;
		key_sound = ON;
		main_menu_select_bar--;
		if(main_menu_select_bar < 1)
			main_menu_select_bar = 7;
		Main_Menu_Bar_Display();
	}

	if(key_code == ENTER_KEY)
	{
		key_code = 0;
		key_sound = ON;
//		led_on_off_data = 0x08;
//		RemoveOSDFnt();
		RemoveBox();
		sub_menu_on = ON;
		sub_menu_select_bar = 1;
		camera_number = 0;
		sub_menu_select_bar_backup = sub_menu_select_bar;
		switch (main_menu_select_bar) {
			case 1 : 
					menu_page1_system_setup_display();
					break;
			case 2 : 
					menu_page2_display_setup_display();
					Page2_Sub_Menu_Bar_Display(0);
					break;
			case 4 : 
					for(i = 0; i<8; i++)
					{
						Register_Setup(i, 0x00, i%4, 0);
						Register_Setup(i, 0xfe, 0x00, 1);
					}
					menu_page3_camera_setup_display();
					break;
			case 3 : 
	//				Auto_Sequence_Setup_Display();
					menu_page4_auto_sequence_display();
					break;
			case 5 : 
					for(i = 0; i<8; i++)
					{
						Register_Setup(i, 0x00, i%4, 0);
						Register_Setup(i, 0xfe, 0x00, 1);
					}
					WriteAsicByte(MASTER,DVC_PG2, 0x67, 0x86);		//... Motion Cursor Position					
					break;
			case 6 : 
					if(b_video_fmt == NTSC)
						WriteAsicByte(MASTER,DVC_PG1,0x00,0x00);		//... NTSC
					else
						WriteAsicByte(MASTER,DVC_PG1,0x00,0x80);		//... PAL
					menu_page6_event_setup_display();
					break;
			case 7 :	camera_number = 0;
					event_list_page = 0;
					if(b_video_fmt == NTSC)
						WriteAsicByte(MASTER,DVC_PG1,0x00,0x00);		//... NTSC
					else
						WriteAsicByte(MASTER,DVC_PG1,0x00,0x80);		//... PAL
					menu_page7_event_report_display();
					break;
			}
	}
}
#endif
#if 0
//==================================================================================
//
//
//
//
//
//==================================================================================
void Main_Menu_Bar_Display()
{	
	U8 select_mark,N_P;

	if(b_video_fmt == PAL) N_P = 2;
	else N_P = 1;
	select_mark = main_menu_select_bar *2 + 2*N_P;
	
	if(main_menu_select_bar == 1)
	{
              CreateBoxPopHL(PTH_X,BOX_POP_MN, 120, 120, 57, 14);
	}
	else if(main_menu_select_bar == 7)
	{
              CreateBoxPopHL(PTH_X,BOX_POP_MN, 120, 120, 176,14);
	}
	else
	{
              CreateBoxPopHL(PTH_X,BOX_POP_MN, 120, 120, 57 +(main_menu_select_bar -1) *20, 14);
	}
//       CreateBoxPopHL(PTH_X,BOX_POP_MN, 126, 120, 81 +(main_menu_select_bar -1) *14, 14);
}
//==================================================================================
#endif
